package org.hgvc.webapp.ets.jsf.beans.admin;

import java.util.List;

import javax.faces.component.UIParameter;
import javax.faces.event.ActionEvent;

import org.hgvc.webapp.ets.bo.Complaint;
import org.hgvc.webapp.ets.spring.service.ComplaintService;
import org.jocsb.base.AbstractBean;
import org.jocsb.base.exception.BaseException;


public class AdminComplaintBean extends AbstractBean {
	
	public static final String BEAN_NAME="adminComplaintBean";
	private ComplaintService service;
	private List<Complaint> complaintList;
	public static final String NAV_LIST="adminComplaintMgmt";
	public static final String NAV_REPLY="adminReplyComplaint";
	private Complaint complaint;
	
	public String navListAction(){
		return NAV_LIST;
	}
	
	public Complaint getComplaint() {
		return complaint;
	}
	public void setComplaint(Complaint complaint) {
		this.complaint = complaint;
	}
	public ComplaintService getService() {
		return service;
	}
	public void setService(ComplaintService service) {
		this.service = service;
	}
	public List<Complaint> getComplaintList() {
		try{
			complaintList = service.getComplaintList();
		}catch(BaseException be){
			be.printStackTrace();
			initErrorBean(be);
		}
		return complaintList;
	}
	public void setComplaintList(List<Complaint> complaintList) {
		this.complaintList = complaintList;
	}
	
	public String backAction(){
		return AdminPortalBean.NAV_ADMIN_PORTAL;
	}
	
	public void navReplyActionListener(ActionEvent actionEvent){
		UIParameter param = (UIParameter)actionEvent.getComponent().findComponent("compId");
		String id = (String)param.getValue();
		for(Complaint c:complaintList){
			if(c.getComplaintId().equalsIgnoreCase(id)){
				complaint = c;
				break;
			}
		}
	}
	
	public String navReplyAction(){
		return NAV_REPLY;
	}
	
	public String repalyAction(){
		try{
			service.replyComplaint(complaint, getThisUser());
			return NAV_LIST;
		}catch(BaseException be){
			initErrorBean(be);
			be.printStackTrace();
		}
		
		return NAV_REPLY;
	}

}
